package com.hqyj.springBoot.test.dao;

import com.hqyj.springBoot.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author YangGuo
 * @version 1.0
 * @date 2021/8/19 16:01
 */
@Mapper
@Repository
public interface CountryDao {
    /**
     * 通过id查国家
     * @param countryId
     * @return
     */
    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id="countryResults", value = {
            @Result(column = "country_id", property = "countryId"),
            @Result(column = "country_id",
                    property = "cities",
                    javaType = List.class,
                    many = @Many(select="com.hqyj.springBoot.test.dao.CityDao.selectCitesByCountryId")
            )
    })
    Country getCountryByCountryId(int countryId);

    /**
     * 通过国家名和当地国家名查国家
     * @param countryName
     * @param localCountryName
     * @return
     */
    @Select("select * from test_country where country_name = #{countryName} " +
            "and local_country_name = #{localCountryName}")
    @ResultMap(value="countryResults")
    Country getCountryByCountryName(@Param("countryName") String countryName,
                                    @Param("localCountryName") String localCountryName);
}
